//
//  Login_Vc.swift
//  LocaLink
//
//  Created by eme on 2016/12/12.
//  Copyright © 2016年 Icy. All rights reserved.
//

/*
 owner:cy
 update:2016年12月23日21:22:35
 info: 工作
 */
import RxSwift
import UtilCore

class Work_Vc: Base_Vc {
    
    /****************************Storyboard UI设置区域****************************/
    
    @IBOutlet weak var buttons_Cv: UICollectionView!
    @IBOutlet weak var web_Wb: UIWebView!
    
    var webUrl:String = "http://101.200.203.219:920/work.html"
    
    /*----------------------------   自定义属性区域    ----------------------------*/
    var buttons:[(title:String,image:String)] =
        [
            ("Notice","noticeimg"),
            ("Delivery","reportimg"),
            ("Securily Pass","transferimg"),
            ("Report","deliveryimg"),
            ("Service","serviceimg"),
            ("Bookint","holdingimg"),
            ("Vistor","holdingimg"),
            ("More","holdingimg")
    ]
    /****************************Storyboard 绑定方法区域****************************/
    
    
    
    /**************************** 以下是方法区域 ****************************/
    override func viewDidLoad() {
        super.viewDidLoad()
        
    }
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        self.buttons_Cv.reloadData()

        
    }
    
    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)

    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        
    }
    /**
     界面基础设置
     */
    override func setupUI() {
        /**
         *  自定义 导航栏左侧 返回按钮
         */
        self.customLeftBarButtonItem()
//        self.navigationController?.navigationBar.hidden = true
        self.buttons_Cv.backgroundColor = UIColor(hex: "ababab")
        guard let url = NSURL(string:webUrl) else { return  }
        let request = NSMutableURLRequest(url: url as URL)
        self.web_Wb.loadRequest(request as URLRequest)
    }
    
    /**
     绑定到viewmodel 设置
     */
    override func bindToViewModel(){
        
    }
    
    /**
     自定义leftBarButtonItem
     */
    override func customLeftBarButtonItem()  {
        
    }

    
    
}
// MARK: - UICollectionViewDataSource
extension Work_Vc:UICollectionViewDataSource{
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int{
       return buttons.count
    }
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell{
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "WorkButtonsCCell", for: indexPath) as!WorkButtonsCCell
        cell.item = buttons[indexPath.row]
        return cell
    }
    func numberOfSections(in collectionView: UICollectionView) -> Int{
        return 1
    }
}
extension Work_Vc:UICollectionViewDelegate{
    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath){
        
    }
}

extension Work_Vc:UICollectionViewDelegateFlowLayout{
    
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize{
        
        return CGSize(width: (self.buttons_Cv.frame.size.width - 3)/4, height: (self.buttons_Cv.frame.size.height - 4)/2)
        
    }
    
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets{
      return UIEdgeInsets(top: 1, left: 0, bottom: 1, right: 0)
    }
    
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat{
        
        return 1
    }
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat{
         return 1
    }
    
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize{
         return CGSize.zero
    }
    
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForFooterInSection section: Int) -> CGSize{
        return CGSize.zero
    }
}
